//
//  KPAlertController.swift
//  KPBaseProject
//
//  Created by 孑孓 on 2018/4/9.
//  Copyright © 2018年 Kipp. All rights reserved.
//

import UIKit

class KPAlertController: UIAlertController {
    
    var titleFont = UIFont.systemFont(ofSize: 16)
    var titleColor = UIColor.black
    
    var messageFont = UIFont.systemFont(ofSize: 14)
    var messageColor = UIColor.black
    
    var defaultBtnColor = UIColor.black
    
    var cancelBtnColor = UIColor.black
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let titleAttribute = NSMutableAttributedString.init(string: self.title!)
        titleAttribute.addAttributes([NSAttributedStringKey.font : titleFont , NSAttributedStringKey.foregroundColor : titleColor],range:NSMakeRange(0, (self.title?.count)!))
        self.setValue(titleAttribute, forKey: "attributedTitle")
        
        let messageAttribute = NSMutableAttributedString.init(string: self.message!)
        messageAttribute.addAttributes([NSAttributedStringKey.font : messageFont , NSAttributedStringKey.foregroundColor : messageColor],range:NSMakeRange(0, (self.message?.count)!))
        self.setValue(messageAttribute, forKey: "attributedMessage")
        
    }

    override func addAction(_ action: UIAlertAction) {
        super.addAction(action)
        if action.style == .default {
//            action.setValue(defaultBtnFont, forKey: "titleTextFont")
            action.setValue(defaultBtnColor, forKey: "titleTextColor")
        }else{
//            action.setValue(cancelBtnFont, forKey: "titleTextFont")
            action.setValue(cancelBtnColor, forKey: "titleTextColor")
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
